#include "movable.h"

CMovable::CMovable() : CObjects()
{
	isFalling = 0;
	state = 0;
}

CMovable::~CMovable()
{

}

void CMovable::Move(int way,int t)
{
	
}

void CMovable::RenderFrame(LPDIRECT3DDEVICE9 d3ddv, int t)
{
	
}

void CMovable::Update(int t)
{
	pos_x += v_x*t;
	pos_y += v_y*t;
}

void CMovable::isJumpedOn(CObjects *obj)
{}

void CMovable::LoadResources(LPDIRECT3DDEVICE9 d3ddv){}

int CMovable::BeforeMove()
{
	int ii = cTree->Del(pos_x,pos_y,width,height);
	ii = mTree->Del(pos_x,pos_y,1,1);
	return ii;
}

void CMovable::CheckCol()
{
	cTree->Check(pos_x,pos_y+2,width-1,1);

	if(cTree->lastRes == 0 && v_y < 0.5f)
		v_y += 0.1f;
	else if(cTree->lastRes > 0)
	{
		if(ArrayObj[cTree->res[0]]->reality < 3)
		{
			v_y = 0;
			pos_y = ArrayObj[cTree->res[0]]->pos_y - ArrayObj[cTree->res[0]]->height;
		}
	}
	cTree->Check(pos_x+width-1,pos_y-height+5,1,height-10);
	if(cTree->lastRes > 0)
	{
		if(ArrayObj[cTree->res[0]]->reality < 10 || ArrayObj[cTree->res[0]]->reality >= 20)
		{
			pos_x = ArrayObj[cTree->res[0]]->pos_x - width;
			v_x = -v_x;
			movingWay = 0;
		}
	}

	cTree->Check(pos_x+1,pos_y-height+5,1,height-10);
	if(cTree->lastRes > 0)
	{
		if(ArrayObj[cTree->res[0]]->reality < 10 || ArrayObj[cTree->res[0]]->reality >= 20)
		{
			pos_x = ArrayObj[cTree->res[0]]->pos_x + ArrayObj[cTree->res[0]]->width;
			v_x = -v_x;
			movingWay = 1;
		}
	}
}

void CMovable::AfterMove(int ii)
{
	cTree->Add(this,ii);
	mTree->AddPixel(mTree->Root,ii,pos_x,pos_y);
}